﻿using Calligraphy.CalligraphyData;
using Calligraphy.DataModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “基本页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234237 上有介绍

namespace Calligraphy
{
    /// <summary>
    /// 基本页，提供大多数应用程序通用的特性。
    /// </summary>
    public sealed partial class BasicPage1 : Calligraphy.Common.LayoutAwarePage
    {
        public BasicPage1()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// 使用在导航过程中传递的内容填充页。在从以前的会话
        /// 重新创建页时，也会提供任何已保存状态。
        /// </summary>
        /// <param name="navigationParameter">最初请求此页时传递给
        /// <see cref="Frame.Navigate(Type, Object)"/> 的参数值。
        /// </param>
        /// <param name="pageState">此页在以前会话期间保留的状态
        /// 字典。首次访问页面时为 null。</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            double height = Window.Current.Bounds.Height;
            double width = Window.Current.Bounds.Width;
            Ima_fullScrean.Height = height;
            ObservableCollection<object> photo = new ObservableCollection<object>();
            if (navigationParameter is T_RubbingPhoto)
            {
                photo.Add(navigationParameter as T_RubbingPhoto);
                resultsViewSource.Source = photo;
                this.btn_pageTitle.Content = (navigationParameter as T_RubbingPhoto).T_Rubbing.T_StelePaper.Name + " "+(navigationParameter as T_RubbingPhoto).T_Rubbing.Name;
            }
            else
            {
                photo.Add(navigationParameter as T_PaperPhoto);
                resultsViewSource.Source = photo;
                this.btn_pageTitle.Content = (navigationParameter as T_PaperPhoto).T_StelePaper.Name;
            }
        }

        /// <summary>
        /// 保留与此页关联的状态，以防挂起应用程序或
        /// 从导航缓存中放弃此页。值必须符合
        /// <see cref="SuspensionManager.SessionState"/> 的序列化要求。
        /// </summary>
        /// <param name="pageState">要使用可序列化状态填充的空字典。</param>
        protected override void SaveState(Dictionary<String, Object> pageState)
        {
        }

        //private void btn_text_Click_1(object sender, RoutedEventArgs e)
        //{
        //    if (txb_text.Visibility == Visibility.Visible)
        //        txb_text.Visibility = Visibility.Collapsed;
        //    else
        //        txb_text.Visibility = Visibility.Visible;
        //}

        //private void btn_fullScrean_Click_1(object sender, RoutedEventArgs e)
        //{
        //    if (Ima_actually.Visibility == Visibility.Visible)
        //    {
        //        Ima_actually.Visibility = Visibility.Collapsed;
        //        Ima_fullScrean.Visibility = Visibility.Visible;
        //    }
        //    else
        //    {
        //        Ima_fullScrean.Visibility = Visibility.Collapsed;
        //        Ima_actually.Visibility = Visibility.Visible;
        //    }
        //    if ((btn_fullScrean.Name)=="全屏")
        //        btn_fullScrean.Name = "原图";
        //    else
        //        btn_fullScrean.Name = "全屏";
        //}

        private void start(object sender, ManipulationStartedRoutedEventArgs e)
        {
            e.Handled = true;
        }

        private void delta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            Canvas canvas = sender as Canvas;
            this.translatetransform.X += e.Delta.Translation.X;
            this.translatetransform.Y += e.Delta.Translation.Y;
        }

        private void complete(object sender, ManipulationCompletedRoutedEventArgs e)
        {
            e.Handled = true;
        }
        private void onDragDelta_1(object sender, DragDeltaEventArgs e)
        {

            double yadjust = myCanvasStretch.Height + e.VerticalChange;
            double xadjust = myCanvasStretch.Width + e.HorizontalChange;
            if ((xadjust >= 0) && (yadjust >= 0))
            {
                myCanvasStretch.Width = xadjust;
                myCanvasStretch.Height = yadjust;

            }
        }

        private void onDragDelta_2(object sender, DragDeltaEventArgs e)
        {
            double yadjust = myCanvasStretch.Height - e.VerticalChange;
            double xadjust = myCanvasStretch.Width - e.HorizontalChange;
            if ((xadjust >= 0) && (yadjust >= 0))
            {
                myCanvasStretch.Width = xadjust;
                myCanvasStretch.Height = yadjust;

        }
        }
        private void onDragDelta_3(object sender, DragDeltaEventArgs e)
        {
            double yadjust = myCanvasStretch.Height + e.VerticalChange;
            double xadjust = myCanvasStretch.Width - e.HorizontalChange;
            if ((xadjust >= 0) && (yadjust >= 0))
            {
                myCanvasStretch.Width = xadjust;
                myCanvasStretch.Height = yadjust;

            }
        }
        private void onDragDelta_4(object sender, DragDeltaEventArgs e)
        {
            double yadjust = myCanvasStretch.Height - e.VerticalChange;
            double xadjust = myCanvasStretch.Width + e.HorizontalChange;
            if ((xadjust >= 0) && (yadjust >= 0))
            {
                myCanvasStretch.Width = xadjust;
                myCanvasStretch.Height = yadjust;

            }
        }
      
       
        
        
        private void inertiastart(object sender, ManipulationInertiaStartingRoutedEventArgs e)
        {
            e.TranslationBehavior.DesiredDeceleration = 10;
        }
        private void btn_pageTitle_Click_1(object sender, RoutedEventArgs e)
        {
            //if (e.ClickedItem is T_RubbingPhoto)
            //{
            //    
            //}
            //else
            //{
            //    
            //}
            Array a = resultsViewSource.View.ToArray();
            if (a.GetValue(0) is T_RubbingPhoto)
            {

                //RubbingPhotoesDataSource rpds = new RubbingPhotoesDataSource();
                //rpds.LoadRubbingPhotoes((a.GetValue(0) as T_RubbingPhoto).T_Rubbing);
                this.Frame.Navigate(typeof(CustomRubbingPhoto), a.GetValue(0) as T_RubbingPhoto);
            }
            else
            {
                //PaperPhotoesDataSource.LoadPaperPhotoesByPaperPhoto(a.GetValue(0) as T_PaperPhoto);
                this.Frame.Navigate(typeof(CustomRubbingPhoto), a.GetValue(0) as T_PaperPhoto);
            }
        }
        private void ShowMessage_Click(object sender, RoutedEventArgs e)
        {
            if (this.myCanvasStretch.Visibility == Visibility.Collapsed)
            {
                this.myCanvasStretch.Visibility = Visibility.Visible;

            }
            else
            {
                this.myCanvasStretch.Visibility = Visibility.Collapsed;

            }
        }
    }
}
